﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Data;
using ClassLibrary.Entity;

public partial class Admin_Account : System.Web.UI.Page
{
    TblAccountsDAO AccountDAO = new TblAccountsDAO(Global.CONNECTION_STRING);
    TblAlbumImagesDAO AlbumDAO = new TblAlbumImagesDAO(Global.CONNECTION_STRING);
    TblImagesDAO ImageDAO = new TblImagesDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string IDAcc = Request.QueryString["IDAcc"];
            string IDAl = Request.QueryString["IDAl"];
            if (IDAcc != null || IDAcc != "")
            {
                LoadAcountById();
                LoadListAlbumByIDAcc();
            }
            if (IDAl != null || IDAl != "")
            {
                pnImage.Visible = true;
                LoadImageByIDAl();
            }
            else
            {
                pnImage.Visible = false;
            }
        }
    }

    private void LoadImageByIDAl()
    {
        string IDAl = Request.QueryString["IDAl"];
        reImage.DataSource = ImageDAO.GetImageByIdAlbum(Convert.ToInt32(IDAl));
        reImage.DataBind();
    }


    private void LoadListAlbumByIDAcc()
    {
        string IDAcc = Request.QueryString["IDAcc"];
        grdListAlbum.DataSource = AlbumDAO.GetAlbumsByIDAcc(Convert.ToInt32(IDAcc));
        grdListAlbum.DataBind();
    }

    private void LoadAcountById()
    {
        string IDAcc=Request.QueryString["IDAcc"];
        TblAccounts account = AccountDAO.GetAccountById(Convert.ToInt32(IDAcc));
        txtFName.Text = account.FirstName;
        txtLName.Text = account.LastName;
        txtEmail.Text = account.EmailAcc;
        txtUserName.Text = account.UsernameAcc;
        txtPhone.Text = account.PhoneNumber;
        txtCountry.Text = account.Country;
        txtDateReg.Text = account.DateRegister.ToString("dd/MM/yyyy");
        txtDateExpiry.Text = account.DateExpiry.ToString("dd/MM/yyyy");
    }

    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        int IDAl = Convert.ToInt32(((ImageButton)sender).CommandArgument);
        string IDAcc = Request.QueryString["IDAcc"];
        //string IDAl = Request.QueryString["IDAl"];

        Response.Redirect("~/Admin/Account.aspx?IDAcc=" + IDAcc + "&IDAl=" + IDAl);
        //Response.Redirect("~/Admin/GetLayoutCode.aspx?idLayout=" + IDLayout);
        //Response.Redirect("~/Admin/Account.aspx?IDAcc=" + IDAcc);
    }
}
